# Contributor: Oleg Titov <oleg.titov@gmail.com>
# Maintainer: Oleg Titov <oleg.titov@gmail.com>
pkgname=kubo
pkgver=0.31.0
pkgrel=0
_migration=fs-repo-15-to-16/v1.0.0
pkgdesc="Inter Platnetary File System (IPFS), a peer-to-peer hypermedia distribution protocol"
url="https://ipfs.tech/"
arch="x86_64 x86 aarch64 armhf armv7"
license="MIT Apache-2.0"
pkgusers="ipfs"
pkggroups="ipfs"
options="!check chmod-clean" # No test suite from upstream
makedepends="go bash"
install="$pkgname.pre-install $pkgname.post-install"
subpackages="$pkgname-doc $pkgname-migration $pkgname-openrc $pkgname-bash-completion"
source="$pkgname-$pkgver.tar.gz::https://github.com/ipfs/kubo/archive/refs/tags/v$pkgver.tar.gz
	$pkgname-migration-${_migration/\//-}.tar.gz::https://github.com/ipfs/fs-repo-migrations/archive/refs/tags/$_migration.tar.gz
	ipfs.initd
	ipfs.confd
	"
provides="go-ipfs=$pkgver-r$pkgrel"
replaces="go-ipfs"

# secfixes:
#   0.28.0-r0:
#     - CVE-2024-22189
#   0.8.0-r0:
#     - CVE-2020-26279
#     - CVE-2020-26283

export GOBIN="$GOPATH/bin"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make build

	# build bash completion
	./cmd/ipfs/ipfs commands completion bash > $pkgname.bash

	cd "$srcdir"/fs-repo-migrations-${_migration/\//-}/fs-repo-15-to-16
	go build
}

package() {
	install -m755 -D cmd/ipfs/ipfs \
		"$pkgdir"/usr/bin/ipfs

	install -m755 -D "$srcdir"/fs-repo-migrations-${_migration/\//-}/fs-repo-15-to-16/fs-repo-15-to-16 \
		-t "$pkgdir"/usr/bin

	install -m644 -D -t "$pkgdir/usr/share/doc/$pkgname" README.md

	install -m755 -D "$srcdir"/ipfs.initd \
		"$pkgdir"/etc/init.d/ipfs
	install -m644 -D "$srcdir"/ipfs.confd \
		"$pkgdir"/etc/conf.d/ipfs

	install -Dm644 $pkgname.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname

	install -dm750 -o ipfs -g ipfs "$pkgdir"/var/lib/ipfs
	install -dm755 "$pkgdir"/var/log/ipfs
}

migration() {
	pkgdesc="$pkgdesc (15 to 16 migration)"

	amove usr/bin/fs-repo-*
}

sha512sums="
86fdfbbb1694d7625ad49bfb3e5b2567c118d50950ce106f0723579872d166769e802292495c432ef02ec71c8d6ef6f21c3fc145f6af151270c607e4175e281f  kubo-0.31.0.tar.gz
f2af30988033c3e80ee45cca0f67ab39f1f0089bc94378bf0e8b32a438d6b0448d8ce37f149a2db2a6a8d869e6aaddae8539f5d7286e4e8d70b2d78c7b1d837e  kubo-migration-fs-repo-15-to-16-v1.0.0.tar.gz
3e51e9a3dca1b991e8549f8354f7c2cfd1bb9b73d7a59557878d5c9ab4189988676d789172af3ba1fd57193ec48ca9125919507b0de7d0400ce0d6166622e556  ipfs.initd
c55afeb3efe381d18258ddf00f58325b77156375cf223fb2daa049df056efe22e9139cce0f81dc4c73759dad5097af5f3201414beb5950bd894df9ae8c7c4ed1  ipfs.confd
"
